package api

import (
	"RESTful-api/basic/config"
	__ "RESTful-api/basic/proto"
	"RESTful-api/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func GetGoodsList(c *gin.Context) {
	var req request.GetGoodsListReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "参数错误",
		})
		return
	}
	list, err := config.GoodsClient.GoodsList(c, &__.GoodsListReq{
		Id:       int64(req.Id),
		Page:     int64(req.Page),
		PageSize: int64(req.PageSize),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "客户端连接失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "个性化商品推荐列表展示成功",
		"data": list,
	})
}

func GetGoodsDetail(c *gin.Context) {
	var req request.GetGoodsDetailReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "参数错误",
		})
		return
	}
	detail, err := config.GoodsClient.GoodsDetail(c, &__.GoodsDetailReq{
		Id: int64(req.Id),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "客户端连接失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "商品详情查询成功",
		"data": detail,
	})
}
